<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\TestController;
use App\Http\Controllers\LoginController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\GameController;
use App\Http\Controllers\FileController;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::get('test', [TestController::class, 'test']);
Route::get('test2', [TestController::class, 'test2']);

Route::prefix('user')->group(function() {
    Route::post('register', [LoginController::class, 'register']);
    Route::post('login', [LoginController::class, 'login']);
});

Route::middleware('auth:api')->group(function() {

    Route::post('user/logout', [LoginController::class, 'logout']);

    Route::apiResource('user', UserController::class)
    ->parameter('user', 'id')
    ->only('index','show', 'update');

    Route::prefix('game')->group(function() {
        Route::get('record/{id}', [GameController::class, 'userRecord']);
        Route::get('ranking', [GameController::class, 'ranking']);
        Route::post('solve', [GameController::class, 'solve']);
    });

    Route::post('file/upload', [FileController::class, 'upload']);
});